import React from 'react';
import {Button} from "antd";

function isContained(a, b) {
    if (!(a instanceof Array) || !(b instanceof Array)) return false;
    if (a.length < b.length) return false;
    const aStr = a.toString();
    let i = 0, len = b.length;
    for (; i < len; i++) {
        if (aStr.indexOf(b[i]) === -1) return false;
    }
    return true;
}

const Index = (props) => {
    const allPermi = sessionStorage.getItem("ident")
    const {children, haspermi} = props;
    const flag = (haspermi && haspermi.length >= 0 && isContained(allPermi.split(','), haspermi)) || haspermi === undefined;
    return flag && <Button
        {...props}
        style={{
            ...props.otherStyle,
            // 'display': ((haspermi && haspermi.length >= 0 && isContained(allPermi.split(','), haspermi))||haspermi===undefined)  ? '' : 'none'
        }}
    >
        {children}
    </Button>
};

export default Index;
